package com.starmark.sys.org.provider.service.impl;



import com.starmark.sys.org.provider.dto.OrgTreeDto;
import com.starmark.sys.org.provider.service.IOrgAddressService;
import com.starmark.sys.org.provider.service.ISysOrgCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 组织服务Service
 *
 * @author starmark
 * @create 2018-05-01 20:43
 **/

@Service("orgAddressService")
public class OrgAddressServiceImpl implements IOrgAddressService {

    @Autowired
    private List<ISysOrgCommonService> sysOrgCommonServices;


    @Override
    public List<OrgTreeDto> getOrgTreeBySearchkey(int orgType,
                                                  String searchKey,
                                                  int pageSize) {
        List<OrgTreeDto> orgTreeDtos = new ArrayList<>();
        for (ISysOrgCommonService sysOrgCommonService : sysOrgCommonServices) {
            if (sysOrgCommonService.isSearch(orgType)) {
                orgTreeDtos.addAll(sysOrgCommonService.getOrgTreeBySearchkey(searchKey, pageSize));
            }
        }
        return orgTreeDtos;

    }


    @Override
    public List<OrgTreeDto> getOrgTreeById(int orgType, String id) {
        List<OrgTreeDto> orgTreeDtos = new ArrayList<>();
        for (ISysOrgCommonService sysOrgCommonService : sysOrgCommonServices) {
            if (sysOrgCommonService.isTree(orgType)) {
                orgTreeDtos.addAll(sysOrgCommonService.getOrgTreeById(id));
            }
        }
        return orgTreeDtos;
    }


}
